﻿@model SimpComm.PagedModel
@{ int bt1 = 2, bt2 = 2, ShowTabNum = bt1 + bt2 + 1; }
@if (Model.TotalRecordCount > Model.PageSize)
{
    <div class="row-fluid">
        <div class="span12">
            <div class="pagination pagination-right">
                <ul>
                    @{

    //获取第一页和最后一页
    var startPageIndex = Math.Max(1, Model.CurrentPageIndex - bt1);
    var endPageIndex = Math.Min(Math.Max(ShowTabNum, Model.CurrentPageIndex + bt2), Model.PageCount);
    // 显示第回到首页
    if (startPageIndex >= bt1)
    {
        Html.RenderPartial("~/Views/Tool/_PagerLink.cshtml", Model,
                           new ViewDataDictionary
                                                   {
                                                       {"Text", "«"},
                                                       {"PageIndex", 1},
                                                       {"Selected", false},
                                                       {"Inactive", Model.CurrentPageIndex == 1},
                                                       {"MyRoutes", Model.MyRoutes},
                                                   });
        //显示上面N页
        if (startPageIndex > ShowTabNum)
        {
            Html.RenderPartial("~/Views/Tool/_PagerLink.cshtml", Model,
                               new ViewDataDictionary
                                                       {
                                                           {"Text", ".."},
                                                           {"PageIndex", Model.CurrentPageIndex - ShowTabNum},
                                                           {"Selected", false},
                                                           {"Inactive", Model.CurrentPageIndex == 1},
                                                           {"MyRoutes", Model.MyRoutes},
                                                       });
        }
    }


    // 添加中间的页码 如： 上一页 1 2 3 4 下一页
    for (var i = startPageIndex; i <= endPageIndex; i++)
    {
        Html.RenderPartial("~/Views/Tool/_PagerLink.cshtml", Model,
                           new ViewDataDictionary
                                                   {
                                                       {"Text", i},
                                                       {"PageIndex", i},
                                                       {"Selected", Model.CurrentPageIndex==i},
                                                       {"Inactive", Model.CurrentPageIndex == 1},
                                                       {"MyRoutes", Model.MyRoutes},
                                                   });
    }

    if (Model.PageCount > ShowTabNum)
    {

        // 显示最后一页
        if (endPageIndex <= Model.PageCount - bt2 + 1)
        {
            //显示上面N页
            if (endPageIndex < Model.PageCount - ShowTabNum + 1)
            {
                Html.RenderPartial("~/Views/Tool/_PagerLink.cshtml", Model,
                                   new ViewDataDictionary
                                                           {
                                                               {"Text", ".."},
                                                               {"PageIndex", endPageIndex + ShowTabNum},
                                                               {"Selected", false},
                                                               {"Inactive", Model.CurrentPageIndex == 1},
                                                               {"MyRoutes", Model.MyRoutes},
                                                           });
            }
            Html.RenderPartial("~/Views/Tool/_PagerLink.cshtml", Model,
                               new ViewDataDictionary
                                                       {
                                                           {"Text", "»"},
                                                           {"PageIndex", Model.PageCount},
                                                           {"Selected", false},
                                                           {"Inactive", Model.CurrentPageIndex == 1},
                                                           {"MyRoutes", Model.MyRoutes},
                                                       });

        }
    }
                    }
                </ul>
                <div>
                    共 @Model.TotalRecordCount 条数据. 每页显示 @Model.PageSize 条 / 共 @Model.PageCount 页</div>
            </div>
        </div>
    </div>
}
